﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using Cesave.DistributedServices.Core.ErrorHandlers;
using Cesave.Domain.PermisosModule.Contracts.FoliosPermisos;
using Cesave.Infrastructure.CrossCutting.IoC;
using Cesave.Infrastructure.CrossCutting.Logging;

namespace Cesave.DistributedServices.PermisosModule
{
	public partial class PermisosModuleService
	{
		#region IPermisosModuleService Members
		
		/// <summary>
		/// 
		/// </summary>
		/// <param name="folio"></param>
		public void AddFoliosPermiso(Domain.PermisosModule.Entities.FoliosPermiso folio)
		{
			try
			{
				IFoliosPermisoService foliosPermisoService = IoCFactory.Resolve<IFoliosPermisoService>();
				foliosPermisoService.AddFoliosPermiso(folio);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="folio"></param>
		public void ChangeFoliosPermiso(Domain.PermisosModule.Entities.FoliosPermiso folio)
		{
			try
			{
				IFoliosPermisoService foliosPermisoService = IoCFactory.Resolve<IFoliosPermisoService>();
				foliosPermisoService.ChangeFoliosPermiso(folio);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="juntaGuid"></param>
		/// <param name="cicloGuid"></param>
		/// <param name="areaGuid"></param>
		/// <returns></returns>
		public int IncreaseFoliosPermiso(Guid juntaGuid, Guid cicloGuid, Guid areaGuid)
		{
			try
			{
				IFoliosPermisoService foliosPermisoService = IoCFactory.Resolve<IFoliosPermisoService>();
				return foliosPermisoService.IncreaseFoliosPermiso(juntaGuid, cicloGuid, areaGuid);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="juntaGuid"></param>
		/// <param name="cicloGuid"></param>
		/// <param name="areaGuid"></param>
		/// <returns></returns>
		public Domain.PermisosModule.Entities.FoliosPermiso FindFolioPermisoByJuntaAndCicloAndArea(Guid juntaGuid, Guid cicloGuid, Guid areaGuid)
		{
			try
			{
				IFoliosPermisoService foliosPermisoService = IoCFactory.Resolve<IFoliosPermisoService>();
				return foliosPermisoService.FindFolioPermisoByJuntaAndCicloAndArea(juntaGuid, cicloGuid, areaGuid);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="juntaGuid"></param>
		/// <param name="cicloGuid"></param>
		/// <returns></returns>
		public List<Domain.PermisosModule.Entities.FoliosPermiso> FindFoliosPermisoByJuntaAndCiclo(Guid juntaGuid, Guid cicloGuid)
		{
			try
			{
				IFoliosPermisoService foliosPermisoService = IoCFactory.Resolve<IFoliosPermisoService>();
				return foliosPermisoService.FindFoliosPermisoByJuntaAndCiclo(juntaGuid, cicloGuid);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

		#endregion
	}
}